package com.foreknow.oopTest;

/**
 * @author shkstart
 * @create 2021-07-23 13:48
 */
public class Student {
    private String name;//姓名
    private String id;   //学号
    private double grade;  //成绩


    public Student() {
    }

    public Student(String name, String id, double grade) {
        this.name = name;
        this.id = id;
        this.grade = grade;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public double getGrade() {
        return grade;
    }

    public void setGrade(double grade) {
        this.grade = grade;
    }


    /**
     * 按成绩排序
     *
     * @param arry
     * @return
     */
    public Student[] sort(Student[] arry) {
        Student temp = new Student();
        for (int i = 0; i < arry.length; i++) {
            for (int j = 0; j < arry.length - i - 1; j++) {
                if (arry[j].getGrade() < arry[j + 1].getGrade()) {
                    temp = arry[j];
                    arry[j] = arry[j + 1];
                    arry[j + 1] = temp;
                }
            }
        }
        return arry;
    }

    public static void main(String[] args) {
        Student s1 = new Student("a", "1", 88);
        Student s2 = new Student("b", "2", 65);
        Student s3 = new Student("c", "3", 87);
        Student s4 = new Student("d", "4", 99);
        Student s5 = new Student("e", "5", 66);
        Student[] stu = new Student[5];
        stu[0] = s1;
        stu[1] = s2;
        stu[2] = s3;
        stu[3] = s4;
        stu[4] = s5;
        Student[] newstu = new Student[stu.length];
        Student s = new Student();
        newstu = s.sort(stu);
        for (int i = 0; i < newstu.length; i++) {
            System.out.println("姓名" + newstu[i].getName() + ",学号" + newstu[i].getId() + ",成绩" + newstu[i].getGrade());
        }
    }

}

